export const flat = function (arr) {
    let result = []
    arr.forEach(item => {
        if (Array.isArray(item)) {
            result.push(flat(item))
        } else {
            result.push(item)
        }    
    });
    return result
}

export const reduceFlat = function (arr, depth) {
    return depth > 0 ? arr.reduce((pre, cur) => {
        return pre.concat(Array.isArray(cur) ? reduceFlat(cur, depth - 1) : cur)
    }, [])
    : arr.slice()
}